package com.edu.service.load.impl;

import com.edu.entity.queryanswer.Querypage;
import com.edu.entity.resource.Resource;
import com.edu.mapper.load.LoadMapper;
import com.edu.service.load.LoadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LoadServiceImpl implements LoadService {
    private static Integer CURRENT_PAGE=1;
    private static Integer PAGE_SIZE=10;
    @Autowired
    private LoadMapper loadMapper;
    @Override
    public void insertfile(Resource resource) {
        loadMapper.upload(resource);
    }

    @Override
    public List<Resource> findlist(Integer page,Integer size) {
        if (page != null){
            CURRENT_PAGE=page;
        }
        if (size!=null){
            PAGE_SIZE=size;
        }
        Querypage querypage=new Querypage((CURRENT_PAGE-1)*PAGE_SIZE,PAGE_SIZE);
        return loadMapper.findlist(querypage);
    }

    @Override
    public List<Resource> findByName(String resourceName,Integer page,Integer size) {
        System.out.println("ppppp");
        if (page != null){
            CURRENT_PAGE=page;
        }
        if (size!=null){
            PAGE_SIZE=size;
        }
        System.out.println("%"+resourceName+"%");
        return loadMapper.findByName("%"+resourceName+"%",(CURRENT_PAGE-1)*PAGE_SIZE,PAGE_SIZE);
    }

    @Override
    public Resource findById(Integer id) {
        return loadMapper.findById(id);
    }

    @Override
    public int gettotal(String resourceName) {
        return loadMapper.gettotal(resourceName);
    }
}
